package com.dbMethod;

import com.lUtils.jdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;



//修改用户密码
public class sql_AlterPassword {

    /**
     * 修改密码
     * @param password 密码
     * @param CardId   卡号
     * @return 受影响的行数
     */

    public static int AlterPassword(int password,String CardId) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int rowsAffected=0;
        try{
            con= jdbcUtils.getConnection();
            ps=con.prepareStatement("UPDATE `cardinfo`  SET `password`=? WHERE `cardID`=?");
            ps.setInt(1,password);
            ps.setString(2, CardId);
            //指向查询的语句要使用executeQuery，而不是executeUpdate()
            rowsAffected =ps.executeUpdate();
            return rowsAffected;

        }catch (SQLException e){
            e.printStackTrace();
            return rowsAffected;
        }
        finally {
            jdbcUtils.closeTheStream(rs, ps, con);
        }

    }
}
